import matplotlib.pyplot as plt
from PIL import Image
import torchvision.transforms as transforms
import os
os.environ['KMP_DUPLICATE_LIB_OK']='True'
# 读取图片
img = Image.open("archive/mini-test/Image_1.jpg")  # 替换"example.jpg"为你的图片路径

# 定义转换
mean = [0.5, 0.5, 0.5]
# std = [0.25, 0.25, 0.25]
std = [0.5, 0.5, 0.5]
transform = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.RandomHorizontalFlip(),
    transforms.ToTensor(),
    transforms.Normalize(mean, std),
    transforms.ToPILImage()
])

# 应用转换
new_img = transform(img)

# 展示原始图片和转换后的图片
fig, axes = plt.subplots(1, 2, figsize=(10, 5))
axes[0].imshow(img)
axes[0].set_title('Original Image')
axes[0].axis('off')

axes[1].imshow(new_img)
axes[1].set_title('Transformed Image')
axes[1].axis('off')

plt.tight_layout()
plt.show()
